package com.qq2008.game.mojie.service.impl;

import com.qq2008.game.mojie.form.JSONResult;
import com.qq2008.game.mojie.form.Result;
import com.qq2008.game.mojie.jdo.User;
import com.qq2008.game.mojie.mapper.UserMapper;
import com.qq2008.game.mojie.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public User get(Map<String, Object> param) {
        return userMapper.get(param);
    }

    @Override
    public List<Integer> allID() {
        return userMapper.allID();
    }

    @Override
    public JSONResult checkLoginNameAndPassword(String loginName, String password) {

        JSONResult JSONResult = com.qq2008.game.mojie.form.JSONResult.jsonResult(0, true, Result.CODE_OK, "", null, null);

        // 账号校验
        if (loginName.trim().length() < 6 || loginName.trim().length() > 16) {
            JSONResult.setMessage("账号格式不正确");
            JSONResult.setFlag(false);
        }

        // 密码校验
        if (password.trim().length() < 6 || password.trim().length() > 16) {
            JSONResult.setMessage("密码格式不正确");
            JSONResult.setFlag(false);
        }

        return JSONResult;
    }

    @Override
    public int register(User user) {
        return userMapper.register(user);
    }

    @Override
    public void logLogin(Map<String, Object> param) {
        userMapper.logLogin(param);
    }
}
